<template>
  <div>
    <!-- 頭部滾動 -->
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a class="mui-control-item" v-for="count in 8" :key="count" @click="getPage(count)">美女{{count}}</a>
        </div>
      </div>
    </div>

    <ul class="img-list">
      <li v-for="item in list" :key="item.id">
        <img v-lazy="item.img" />
      </li>
    </ul>
  </div>
</template>
<script>
import mui from "../../lib/mui/js/mui.js";

export default {
  data() {
    return {
      list: [],
      page: 1
    };
  },
  methods: {
    getLazyImh() {
      this.$http
        .get("https://api.apiopen.top/getImages?count=20&page=" + this.page)
        .then(r => {
          if (r.body.code == 200) {
            this.list = r.body.result;
          }
        });
    },
    getPage(i) {
      this.page = i;
      this.getLazyImh();
    }
  },

  created() {
    this.getLazyImh();
  },
  //一般操作元素的放在mounted
  mounted() {
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  }
};
</script>
<style lang="less" scoped>
.mui-segmented-control.mui-scroll-wrapper .mui-control-item {
  padding: 0 20rem/100;
}
.img-list {
  margin: 0;
  padding: 0;
  padding-bottom: 60px;
  li {
    list-style: none;
    margin: 20rem/100;
    border-radius: 20rem/100;
    text-align: center;
    background-color: #ccc;
    overflow: hidden;
    box-shadow: 6px 1px 3px rgba(0, 0, 0, 0.4);
    img {
      width: 100%;
    }
    img[lazy="loading"] {
      width: 40px;
      height: 300px;
      margin: auto;
    }
  }
}
</style>
